﻿#include <sstream>

#include "zyXMLRes.h"


// Base64 编码表
const wchar_t base64_encode_table[65] = {
    L'A', L'B', L'C', L'D', L'E', L'F', L'G', L'H', L'I', L'J', L'K', L'L', L'M', L'N', L'O',
    L'P', L'Q', L'R', L'S', L'T', L'U', L'V', L'W', L'X', L'Y', L'Z', L'a', L'b', L'c', L'd',
    L'e', L'f', L'g', L'h', L'i', L'j', L'k', L'l', L'm', L'n', L'o', L'p', L'q', L'r', L's',
    L't', L'u', L'v', L'w', L'x', L'y', L'z', L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
    L'8', L'9', L'+', L'/', L'=' // '=' 用于填充
};

// Base64 编码函数
std::wstring BlackMoonUI::zybase64_encode(const std::vector<BYTE>& input) {
    std::wstring output;
    int input_length = static_cast<int>(input.size());
    unsigned char buffer[3] = { 0 };
    int buffer_length = 0;

    for (size_t i = 0; i < input_length;) {
        // 每次读取 3 个字节
        for (int j = 0; j < 3 && i < input_length; ++j, ++i) {
            buffer[j] = input[i];
        }
        buffer_length = i < input_length ? 3 : (input_length % 3);

        // 将 3 个字节转换为 4 个 Base64 字符
        output += base64_encode_table[(buffer[0] >> 2) & 0x3F];
        output += base64_encode_table[((buffer[0] & 0x03) << 4) | ((buffer[1] >> 4) & 0x0F)];

        if (buffer_length > 1) {
            output += base64_encode_table[((buffer[1] & 0x0F) << 2) | ((buffer[2] >> 6) & 0x03)];
        }
        else {
            output += L'='; // 填充字符
        }

        if (buffer_length > 2) {
            output += base64_encode_table[buffer[2] & 0x3F];
        }
        else {
            output += L'='; // 填充字符
        }
    }

    return output;
}
const wchar_t base64_pad_char = L'=';

// Base64 解码表
static const int base64_decode_table[256] = {
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};

std::vector<BYTE> BlackMoonUI::zybase64_decode(const std::wstring& input) {
    std::vector<BYTE> output;
    std::vector<int> buffer(4, 0);
    int buffer_length = 0;

    for (wchar_t ch : input) {
        if (isspace(static_cast<unsigned char>(ch))) continue;
        int value = base64_decode_table[static_cast<unsigned char>(ch)];
        if (value == -1) std::wcout << L"base64_decode character: " << ch << std::endl;//上面编码中用了=号来填充，所以这里会输出=号。但解码时，会忽略掉=号。所以非法字符被忽略或跳过
        buffer[buffer_length++] = value;

        if (buffer_length == 4) {
            output.push_back((buffer[0] << 2) | ((buffer[1] & 0x30) >> 4));
            output.push_back(((buffer[1] & 0x0F) << 4) | ((buffer[2] & 0x3C) >> 2));
            output.push_back(((buffer[2] & 0x03) << 6) | (buffer[3] & 0x3F));
            buffer_length = 0;
        }
    }

    if (buffer_length > 0) {
        for (int i = buffer_length; i < 4; ++i) {
            buffer.push_back(base64_decode_table[static_cast<unsigned char>(base64_pad_char)]);
        }
        output.push_back((buffer[0] << 2) | ((buffer[1] & 0x30) >> 4));
        if (buffer_length > 1) {
            output.push_back(((buffer[1] & 0x0F) << 4) | ((buffer[2] & 0x3C) >> 2));
            if (buffer_length == 3) {
                output.back() &= 0x3F; // 如果只有一个填充字符，则最后一个解码的字节的后 2 位应为 0
            }
        }
    }

    return output;
}


HWND BlackMoonUI::zyXMLRes::黑月创建资源控件(zyWindow& 参数_父窗口, const std::wstring& 参数_控件XML) {//返回控件指针
    pugi::xml_document xmlDoc;
    pugi::xml_parse_result result = xmlDoc.load_string(参数_控件XML.c_str());
    // 检查解析是否成功
    if (result.status != pugi::status_ok) {
        return 0; 
    }
    pugi::xml_node windowNode = xmlDoc.first_child();
    HWND pCtrl = xml_ParseNodeCreateControl(&windowNode,参数_父窗口.getHwnd(), NULL);
    return pCtrl;
}
HWND BlackMoonUI::zyXMLRes::黑月创建资源控件(zyWindow& 参数_父窗口, pugi::xml_node 参数_控件节点) {//返回控件指针

    HWND pCtrl = XMLRES_CreateControl(参数_控件节点, 参数_父窗口.getHwnd());
    return pCtrl;
}
HWND BlackMoonUI::zyXMLRes::黑月创建资源控件(HWND 参数_父窗口, pugi::xml_node 参数_控件节点) {//返回控件指针

    HWND pCtrl = XMLRES_CreateControl(参数_控件节点, 参数_父窗口);
    return pCtrl;
}
BlackMoonUI::zyXMLRes::zyXMLRes()
{
	m_obj->setDestroy(zyXMLRes_Destroy);
}
BlackMoonUI::zyXMLRes::~zyXMLRes()
{

}
bool BlackMoonUI::zyXMLRes::Initialize() {
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    if (!xmlDoc) {
        // 创建一个新的 XML 文档并转移所有权
        std::unique_ptr<pugi::xml_document> newXmlDoc = std::make_unique<pugi::xml_document>();
        // 设置成员指针
        SetMember(reinterpret_cast<LONG_PTR>(newXmlDoc.release()));
        xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    }
    // 清空所有子节点
    xmlDoc->reset();

    // 创建 XML 声明节点
    pugi::xml_node pi = xmlDoc->append_child(pugi::node_declaration);
    pi.append_attribute(L"version") = "1.0";
    pi.append_attribute(L"encoding") = "UTF-8";
    
    // 创建自定义处理指令节点
    pugi::xml_node pi_zyBMUI = xmlDoc->append_child(L"zyBMUI");
    pi_zyBMUI.append_attribute(L"version") = "1.0";
    return true;
}
bool BlackMoonUI::zyXMLRes::LoadXml(const std::wstring& xmlContent) {
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    if (!xmlDoc) {
        return false; // 如果 xmlDoc 为空，返回失败
    }
    // 使用 pugixml 解析 XML 内容
    //pugi::xml_parse_result result = xmlDoc->load_string(xmlContent.c_str());
    std::vector<CHAR> pLayout;
    zyReadFile(xmlContent.c_str(), &pLayout);
    //std::vector<BYTE> pLayout = ReadFileToBinary(xmlContent);
    //SaveBinaryToHeaderFile(pLayout, L"BlackMoonUI.h",L"mian_i");
    pugi::xml_parse_result result = xmlDoc->load_buffer(pLayout.data(), pLayout.size());
    // 检查解析是否成功
    if (result.status == pugi::status_ok) {
        return true; // 解析成功
    }
    else {
        std::wcout << L"LoadXml-XML 解析失败: " << result.description() << std::endl;
        return false; // 解析失败
    }
}
bool BlackMoonUI::zyXMLRes::LoadXml_wstring(const std::wstring& xmlContent) {
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    if (!xmlDoc) {
        return false; // 如果 xmlDoc 为空，返回失败
    }
    // 使用 pugixml 解析 XML 内容
    pugi::xml_parse_result result = xmlDoc->load_string(xmlContent.c_str());
    // 检查解析是否成功
    if (result.status == pugi::status_ok) {
        return true; // 解析成功
    }
    else {
        std::wcout << L"XML 解析失败: " << result.description() << std::endl;
        return false; // 解析失败
    }
}
// 取Xml 函数
std::wstring BlackMoonUI::zyXMLRes::取Xml(bool 参数_自动格式 /* = true */) {
    // 获取 XML 文档指针并检查有效性
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    if (!xmlDoc) {
        return L"";
    }
    // 提前计算缩进字符串
    std::wstring indent = 参数_自动格式 ? L"  " : L"";

    // 使用 wstringstream 进行 XML 序列化
    std::stringstream ss;
    xmlDoc->save(ss, indent.c_str(), pugi::format_default, pugi::encoding_utf8);

    // 将 UTF-8 字符串转换为 std::wstring
    std::string utf8_str = ss.str();
    if (utf8_str.empty()) return L"";

    // 使用 Windows API 转换 UTF-8 到 UTF-16
    int wchars_needed = ::MultiByteToWideChar( CP_UTF8, 0, utf8_str.c_str(), (int)utf8_str.size(), NULL, 0 );
    std::wstring wstr;
    wstr.resize(wchars_needed);
    ::MultiByteToWideChar( CP_UTF8, 0, utf8_str.c_str(), (int)utf8_str.size(),  &wstr[0], wchars_needed );

    return wstr;
}
bool BlackMoonUI::zyXMLRes::载入菜单栏(const std::wstring& 参数_资源名, zyMenu& 参数_菜单) {//从XML资源载入菜单，标签为<菜单栏>
    return xml_LoadMenu(参数_资源名.c_str(), 参数_菜单);
}
bool BlackMoonUI::zyXMLRes::载入菜单栏(pugi::xml_node node, const std::wstring& name, zyMenu& menu)
{
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//菜单栏[@名称='" + name + L"']";
    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = node.select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcerr << L"xml_LoadMenu查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node menuNode = xpathNode.node();
    //pugi::xml_node node2 = pnode->next_sibling(L"菜单栏");
    if (!menuNode) {
        std::wcout << L"节点 菜单栏 获取失败!" << std::endl;
        return false;
    }
    if (!menu.创建菜单栏())
        return false;
    xml_LoadMenuItem(menuNode, menu);
    return true;
}
bool BlackMoonUI::zyXMLRes::载入弹出菜单(const std::wstring& 参数_资源名, zyMenu& 参数_菜单) {//从XML资源载入菜单，标签为<子菜单>
    return xml_LoadSubMenu(参数_资源名.c_str(), 参数_菜单);
}
bool BlackMoonUI::zyXMLRes::创建窗口(HWND 参数_父窗口, const std::wstring& 参数_资源名, zyWidget& 参数_窗口, bool 参数_隐藏)
{
    if (参数_窗口.是否已创建()){
        return false;
    }
 //   std::vector<CHAR> pLayout;
 //   zyReadFile(参数_XML.c_str(), &pLayout);
	//pugi::xml_document doc;
	//// 加载 XML 文件内容到 pugi::xml_document
	//pugi::xml_parse_result result = doc.load_buffer(pLayout.data(), pLayout.size());
	//// 获取根节点
	//pugi::xml_node* root = new pugi::xml_node;
	//*root = doc.child(L"BlackMoonUI").child(L"WindowUI");
	//if (!root) {
	//	std::wcout << "根节点不是BlackMoonUI,加载失败!" << std::endl;
	//	return false;
	//}

    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//"+ std::wstring(zyType_Form) + L"[@名称 = '" + 参数_资源名 + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcout << L"xml创建窗口查询资源名: "<< 参数_资源名 << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node windowNode = xpathNode.node();
    //std::wcout << "  rect: " << windowNode.attribute(L"rect").as_string() << std::endl;
    参数_窗口.SetMember(L"XmlNode", (LONG_PTR)new pugi::xml_node(windowNode));
    参数_窗口.SetRegEvent(L"XmlresOnCreate", TRegEventCallBack(this, &zyXMLRes::_OnXmlresCreate));  //设置从资源创建窗口的创建完毕事件
    
    //GetMember((LONG_PTR)&windowNode);

    std::wstring rc = windowNode.attribute(资源名_矩形).value();
    RECT windowRect = { 0 };
    if(rc.empty())     
        windowRect = { windowNode.attribute(L"左边").as_int(),windowNode.attribute(L"顶边").as_int(),
        windowNode.attribute(L"宽度").as_int(),windowNode.attribute(L"高度").as_int() };
	else
        windowRect = zyStringToRECT(rc.c_str());
    //RECT windowRect = zyStringToRECT(windowNode.attribute(资源名_矩形).value());

	std::wstring windowTitle = windowNode.attribute(资源名_标题).value();

	int border = windowNode.attribute(资源名_边框).as_int();
	if(border != 0) 参数_窗口.边框(border);

    DWORD windowStyle = windowNode.attribute(资源名_窗口风格).as_int(0);

    DWORD windowStyleEx = windowNode.attribute(资源名_扩展风格).as_int(0);

	bool hideTaskbar = windowNode.attribute(资源名_不在任务栏显示).as_bool();

    int value = windowNode.attribute(L"开始位置").as_int();
    if (value != 0)  参数_窗口.置开始位置(value);

    std::wstring classname = windowNode.attribute(资源名_类名).value();
    参数_窗口.setName(参数_资源名);

    if (参数_隐藏)
        windowStyle = (windowStyle & (~WS_VISIBLE));
    else
        windowStyle = (windowStyle | WS_VISIBLE);
    

    bool b = 参数_窗口.创建(参数_父窗口, windowTitle, POINT{ -1,-1 }, 
        POINT{ windowRect.right-windowRect.left,windowRect.bottom -windowRect.top }, windowStyle, windowStyleEx, hideTaskbar);
    return b;
}
bool BlackMoonUI::zyXMLRes::载入窗口(HWND 参数_父窗口, const std::wstring& 参数_资源名, zyWidget& 参数_窗口)
{
    if (参数_窗口.是否已创建()) {
        return false;
    }
    //   std::vector<CHAR> pLayout;
    //   zyReadFile(参数_XML.c_str(), &pLayout);
       //pugi::xml_document doc;
       //// 加载 XML 文件内容到 pugi::xml_document
       //pugi::xml_parse_result result = doc.load_buffer(pLayout.data(), pLayout.size());
       //// 获取根节点
       //pugi::xml_node* root = new pugi::xml_node;
       //*root = doc.child(L"BlackMoonUI").child(L"WindowUI");
       //if (!root) {
       //	std::wcout << "根节点不是BlackMoonUI,加载失败!" << std::endl;
       //	return false;
       //}

    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//" + std::wstring(zyType_Form) + L"[@名称 = '" + 参数_资源名 + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcout << L"查询资源名: " << 参数_资源名 << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node windowNode = xpathNode.node();
    //std::wcout << "  rect: " << windowNode.attribute(L"rect").as_string() << std::endl;
    参数_窗口.SetMember(L"XmlNode", (LONG_PTR)new pugi::xml_node(windowNode));
    参数_窗口.SetRegEvent(L"XmlresOnCreate", TRegEventCallBack(this, &zyXMLRes::_OnXmlresCreate));  //设置从资源创建窗口的创建完毕事件

    //GetMember((LONG_PTR)&windowNode);

    std::wstring rc = windowNode.attribute(资源名_矩形).value();
    RECT windowRect = { 0 };
    if (rc.empty())
        windowRect = { windowNode.attribute(L"左边").as_int(),windowNode.attribute(L"顶边").as_int(),
        windowNode.attribute(L"宽度").as_int(),windowNode.attribute(L"高度").as_int() };
    else
        windowRect = zyStringToRECT(rc.c_str());
    //RECT windowRect = zyStringToRECT(windowNode.attribute(资源名_矩形).value());

    std::wstring windowTitle = windowNode.attribute(资源名_标题).value();

    int border = windowNode.attribute(资源名_边框).as_int();
    if (border != 0) 参数_窗口.边框(border);

    int windowStyle = windowNode.attribute(资源名_窗口风格).as_int(0);

    int windowStyleEx = windowNode.attribute(资源名_扩展风格).as_int(0);

    bool hideTaskbar = windowNode.attribute(资源名_不在任务栏显示).as_bool();

    int value = windowNode.attribute(L"开始位置").as_int();
    if (value != 0)  参数_窗口.置开始位置(value);

    std::wstring classname = windowNode.attribute(资源名_类名).value();
    参数_窗口.setName(参数_资源名);

   
    windowStyle = (windowStyle | WS_VISIBLE);


    bool b = 参数_窗口.载入(参数_父窗口, windowTitle, POINT{ -1,-1 },
        POINT{ windowRect.right - windowRect.left,windowRect.bottom - windowRect.top }, windowStyle, windowStyleEx, hideTaskbar);
    return b;
}
void WINAPI BlackMoonUI::zyXMLRes::zyXMLRes_Destroy(resObject* obj)
{
    LONG_PTR  Node = obj->getDataValue();
    if (Node) {
        delete (pugi::xml_node*)Node;
        obj->setDataValue(0);
    }
	zyRes::zyRes_Destroy(obj);
}

void BlackMoonUI::zyXMLRes::_OnXmlresCreate(zyWidget* form, pugi::xml_node* root){
    xml_SetWinPropertie(form, root);
    XMLRES_置基本属性(form, root);
    xml_ParseNodeCreateControl(root, form->getHwnd(),NULL);

}
void BlackMoonUI::zyXMLRes::xml_SetWinPropertie(zyWidget* form, pugi::xml_node* root)
{
    for (pugi::xml_attribute attr = root->first_attribute(); attr; attr = attr.next_attribute()) {
        const wchar_t* name = attr.name();
        if (wcscmp(name, L"Esc关闭") == 0) {
            form->Esc关闭(attr.as_bool());
        }
        else if (!wcscmp(name, L"保持标题栏激活")) {
            form->保持标题栏激活(attr.as_bool());
        }
        else if (!wcscmp(name, L"背景色")) {
            form->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图)) {
            std::wstring value = attr.value();
            std::wstring 局部_前缀, 局部_值;
            int pos = (int)value.find(L":");
            if (pos == -1) {
                局部_前缀 = L"文件名";
                局部_值 = value;
            }
            else {
                局部_前缀 = value.substr(0, pos);
                局部_值 = value.substr( (pos + 1), value.length() - pos - 1);
            }

            if (!wcscmp(局部_前缀.c_str(), L"文件名"))
                std::wcout << L"文件名" << 局部_值 << std::endl;
            else if (!wcscmp(局部_前缀.c_str(), L"资源名")) {
                // 构造 XPath 查询字符串
                std::wstring xpathQuery = L"//图像[@name='" + 局部_值 + L"']";
                // 使用 XPath 查询节点
                pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
                pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
                if (!xpathNode) {
                    std::wcerr << L"查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
                    continue; // 如果节点未找到，返回失败
                }
                // 获取查询到的节点
                pugi::xml_node menuNode = xpathNode.node();
                //pugi::xml_node node2 = pnode->next_sibling(L"菜单栏");
                if (!menuNode) {
                    std::wcout << L"节点 "<< 局部_值 << L" 获取失败!" << std::endl;
                    continue;
                }
                IStream* pStream = nullptr;
                HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); // 创建一个内存流
                if (FAILED(hr)) {
                    // 处理错误
                }

                // 写入数据到流中
                std::wstring base64Data = menuNode.child_value();
                std::vector<BYTE> output = zybase64_decode(base64Data);
                ULONG bytesWritten = 0;
                hr = pStream->Write(output.data(), (ULONG)output.size() , &bytesWritten); // binaryData是你的字节数组，binaryDataLength是字节数
                if (FAILED(hr)) {
                    // 处理错误
                    pStream->Release(); // 释放流对象
                }

                // 重置流的位置到开始处
                LARGE_INTEGER li = { 0 };
                pStream->Seek(li, STREAM_SEEK_SET, NULL);
                if (FAILED(hr)) {
                    // 处理错误
                    pStream->Release(); // 释放流对象
                    continue;
                }
                Gdiplus::Image* image = Gdiplus::Image::FromStream(pStream);
                if (!image->GetHeight()) {
                    std::wcout << L"背景图创建失败 " << 局部_值 << std::endl;
                    continue;
                }
                form->背景图(image);
                // 释放流对象
                pStream->Release();
            }
           
        }
        else if (!wcscmp(name, L"随意移动")) {
            form->随意移动(attr.as_bool());
        }
        else if (!wcscmp(name, L"图标")) {
            zyIcon icon;
            if(xml_GetIcon(attr.value(), icon))  form->置图标(icon);
        }
        else if (!wcscmp(name, L"菜单")) {
            zyMenu menu;
            if (xml_LoadMenu(attr.value(), menu)) form->置菜单(menu);
        }
        else if (!wcscmp(name, L"快捷键")) {
            //因xml创建事件必须放到 窗口创建之前。放到后面控件会创建不了。但是这里xml布局的快捷键会设置不成功
            //因为快捷键必须在窗口创建完成之后设置才能有效
            //zyAccelTable acc;
            //if (载入快捷键(attr.value(), acc)) form->置快捷键(acc);
        }
        
    }
}

HWND BlackMoonUI::zyXMLRes::XMLRES_CreateControl(pugi::xml_node node, HWND hParent)
{
    if (!node) return NULL;

    HWND pControl = NULL;
    XmlResCreateStruct xrcs = { 0 };

    //pugi::xml_node firstChild = node;
    //if (firstChild) {
    //    pugi::xml_node next = firstChild;
    //    do {
    //        if (next.type() == pugi::node_element) {
    //            xml_GetCtrolCreateStruct(node, xrcs);
    //            std::wstring name = node.name();
    //            // 控件类型判断
    //            if (name == zyType_Button) {
    //                pControl = XMLRES_创建按钮(hParent, xrcs, node);
    //            }
    //            else if (name == zyType_RadioButton) {
    //                pControl = XMLRES_创建单选框(hParent, xrcs, node);
    //            }
    //            else if (name == zyType_CheckButton) {
    //                pControl = XMLRES_创建选择框(hParent, xrcs, node);
    //            }
    //            else if (name == zyType_GroupBox) {
    //                pControl = XMLRES_创建分组框(hParent, xrcs, node);
    //            }
    //            else if (name == zyType_Panel) {
    //                zyPanel* p = XMLRES_创建面板(hParent, xrcs, node);
    //                pControl = p->getHwnd();
    //            }
    //            else if (name == zyType_EditBox) {
    //                pControl = XMLRES_创建编辑框(hParent, xrcs, node);
    //            }
    //            else if (name == zyType_TabControl) {
    //                pControl = XMLRES_创建选择夹(hParent, xrcs, node);
    //                node = node.next_sibling();
    //                continue;
    //            }
    //        

    //            pugi::xml_node nextFirstChild = next.first_child();
    //            if (pControl && nextFirstChild) {
    //                XMLRES_CreateControl(next, pControl);
    //            }
    //        }
    //        next = next.next_sibling();
    //    }while (next);
    //}

    // 处理当前节点
    if (node.type() == pugi::node_element) {
        xml_GetCtrolCreateStruct(node, xrcs);

        const wchar_t* name = node.name();
        
        // 控件类型判断
        if (!wcscmp(name, L"Button") || !wcscmp(name, zyType_Button)) {
            pControl = XMLRES_创建按钮(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"RadioBox") || !wcscmp(name, zyType_RadioButton)) {
            pControl = XMLRES_创建单选框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"CheckBox") || !wcscmp(name, zyType_CheckButton)) {
            pControl = XMLRES_创建选择框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"GroupBox") || !wcscmp(name, zyType_GroupBox)) {
            pControl = XMLRES_创建分组框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"Panel") || !wcscmp(name, zyType_Panel)) {
            zyPanel* p = XMLRES_创建面板(hParent, xrcs, node);
            pControl = p->getHwnd();
        }
        else if (!wcscmp(name, L"Edit") || !wcscmp(name, zyType_EditBox)) {
            pControl = XMLRES_创建编辑框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"TabControl") || !wcscmp(name, zyType_TabControl) ) {
            pControl = XMLRES_创建选择夹(hParent, xrcs, node);
            node = node.next_sibling();
            //return pControl;
        }
        else if (!wcscmp(name, L"ComboBox") || !wcscmp(name, zyType_ComboBox)) {
            pControl = XMLRES_创建组合框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"PictureBox") || !wcscmp(name, zyType_PictureBox)) {
            pControl = XMLRES_创建图片框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ListBox") || !wcscmp(name, zyType_ListBox)) {
            pControl = XMLRES_创建列表框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ShapeBox") || !wcscmp(name, zyType_ShapeBox)) {
            pControl = XMLRES_创建外形框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"Static") || !wcscmp(name, zyType_Label)) {
            pControl = XMLRES_创建标签(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ScrollBar") || !wcscmp(name, zyType_ScrollBar)) {
            pControl = XMLRES_创建滚动条(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ProgressBar") || !wcscmp(name, zyType_ProgressBar)) {
            pControl = XMLRES_创建进度条(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"StatusBar") || !wcscmp(name, zyType_StatusBar)) {
            pControl = XMLRES_创建状态栏(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"TrackBar") || !wcscmp(name, zyType_Trackbar)) {
            pControl = XMLRES_创建滑块条(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ToolBar") || !wcscmp(name, zyType_ToolBar)) {
            pControl = XMLRES_创建工具条(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"AnimateBox") || !wcscmp(name, zyType_Animate)) {
            pControl = XMLRES_创建影像框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ComboBoxEx") || !wcscmp(name, zyType_ComboBoxEx)) {
            pControl = XMLRES_创建图像组合框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"UpDown") || !wcscmp(name, zyType_UpDown)) {
            pControl = XMLRES_创建调节器(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ListBoxEx") || !wcscmp(name, zyType_ListBoxEx)) {
            pControl = XMLRES_创建选择列表框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"MonthCal") || !wcscmp(name, zyType_MonthCal)) {
            pControl = XMLRES_创建月历(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"DateTimePick") || !wcscmp(name, zyType_DateTimePick)) {
            pControl = XMLRES_创建日期框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"IPAddress") || !wcscmp(name, zyType_IPAddress)) {
            pControl = XMLRES_创建IP编辑框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"HotkeyBox") || !wcscmp(name, zyType_Hotkey)) {
            pControl = XMLRES_创建热键框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"LinkBox") || !wcscmp(name, zyType_Link)) {
            pControl = XMLRES_创建超链接框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"AlphaLabel") || !wcscmp(name, zyType_TransparentLabel)) {
            pControl = XMLRES_创建透明标签(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"ListView") || !wcscmp(name, zyType_ListView)) {
            pControl = XMLRES_创建超级列表框(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"CheckBox3State") || !wcscmp(name, zyType_CheckButton3State)) {
            pControl = XMLRES_创建选择框三态(hParent, xrcs, node);
        }
        else if (!wcscmp(name, L"TreeView") || !wcscmp(name, zyType_TreeView)) {
            pControl = XMLRES_创建树型框(hParent, xrcs, node);
        }

        // 递归创建子控件（容器控件特殊处理）
        if (pControl && node.first_child()) {
            // 确定子控件的父窗口
            HWND hChildParent = IsContainerControl(name) ? pControl : hParent;

            pugi::xml_node child = node.first_child();
            while (child) {
                XMLRES_CreateControl(child, hChildParent);
                child = child.next_sibling();
            }
        }
    }

    return pControl;
}

#include <unordered_set>
bool BlackMoonUI::zyXMLRes::IsContainerControl(const wchar_t* type)
{
    static const std::unordered_set<const wchar_t*> containerTypes = {
        zyType_GroupBox,
        zyType_Panel,
        zyType_TabControl,
        zyType_ShapeBox,
        // 其他容器类型...
    };
    return containerTypes.count(type) > 0;
}

HWND BlackMoonUI::zyXMLRes::xml_ParseNodeCreateControl(pugi::xml_node * pnode, HWND parent, HWND childhWnd) {
    // 遍历子节点
    HWND chidhWnd = NULL;
    for (pugi::xml_node node : pnode->children()) {
        // 只处理元素节点，跳过其他类型的节点
        if (node.type() != pugi::node_element) continue;
        
        XmlResCreateStruct res = { 0 };
        xml_GetCtrolCreateStruct(node, res);

        // 根据节点名称设置控件类型和风格
        const wchar_t* classname = node.name();
        bool result = false;
        if (!wcscmp(classname, L"Button") || !wcscmp(classname, zyType_Button)) {
            chidhWnd = XMLRES_创建按钮(parent, res, node);
        }
        else if (!wcscmp(classname, L"Edit") || !wcscmp(classname, zyType_EditBox)) {
            chidhWnd = XMLRES_创建编辑框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"GroupBox") || !wcscmp(classname, zyType_GroupBox)) {
            chidhWnd = XMLRES_创建分组框(parent ? parent : childhWnd, res, node);
            // 如果当前节点有子节点，则递归解析子节点.其他控件如:按钮等相关的不需要处理子节点
            if (node.first_child()) {
                xml_ParseNodeCreateControl(&node, chidhWnd, NULL);
            }
        }
        else if (!wcscmp(classname, L"Panel") || !wcscmp(classname, zyType_Panel)) {
            zyPanel* p = XMLRES_创建面板(parent ? parent : childhWnd, res, node);
            chidhWnd = p->getHwnd();
            // 如果当前节点有子节点，则递归解析子节点.其他控件如:按钮等相关的不需要处理子节点
            if (node.first_child()) {
                xml_ParseNodeCreateControl(&node, NULL, chidhWnd);
            }
        }
        else if (!wcscmp(classname, L"RadioBox") || !wcscmp(classname, zyType_RadioButton)) {
            chidhWnd = XMLRES_创建单选框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"CheckBox") || !wcscmp(classname, zyType_CheckButton)) {
            chidhWnd = XMLRES_创建选择框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"Static") || !wcscmp(classname, zyType_Label)) {
            chidhWnd = XMLRES_创建标签(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ComboBox") || !wcscmp(classname, zyType_ComboBox)) {
            chidhWnd = XMLRES_创建组合框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ListBox") || !wcscmp(classname, zyType_ListBox)) {
            chidhWnd = XMLRES_创建列表框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ScrollBar") || !wcscmp(classname, zyType_ScrollBar)) {
            chidhWnd = XMLRES_创建滚动条(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"PictureBox") || !wcscmp(classname, zyType_PictureBox)) {
            chidhWnd = XMLRES_创建图片框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"TreeView") || !wcscmp(classname, zyType_TreeView)) {
            chidhWnd = XMLRES_创建树型框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ToolBar") || !wcscmp(classname, zyType_ToolBar)) {
            chidhWnd = XMLRES_创建工具条(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"UpDown") || !wcscmp(classname, zyType_UpDown)) {
            chidhWnd = XMLRES_创建调节器(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"TabControl") || !wcscmp(classname, zyType_TabControl)) {
            chidhWnd = XMLRES_创建选择夹(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"StatusBar") || !wcscmp(classname, zyType_StatusBar)) {
            chidhWnd = XMLRES_创建状态栏(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ProgressBar") || !wcscmp(classname, zyType_ProgressBar)) {
            chidhWnd = XMLRES_创建进度条(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"TrackBar") || !wcscmp(classname, zyType_Trackbar)) {
            chidhWnd = XMLRES_创建滑块条(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ListView") || !wcscmp(classname, zyType_ListView)) {
            chidhWnd = XMLRES_创建超级列表框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ShapeBox") || !wcscmp(classname, zyType_ShapeBox)) {
            chidhWnd = XMLRES_创建外形框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"CheckBox3State") || !wcscmp(classname, zyType_CheckButton3State)) {
            chidhWnd = XMLRES_创建选择框三态(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ComboBoxEx") || !wcscmp(classname, zyType_ComboBoxEx)) {
            chidhWnd = XMLRES_创建图像组合框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"ListBoxEx") || !wcscmp(classname, zyType_ListBoxEx)) {
            chidhWnd = XMLRES_创建选择列表框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"MonthCal") || !wcscmp(classname, zyType_MonthCal)) {
            chidhWnd = XMLRES_创建月历(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"DateTimePick") || !wcscmp(classname, zyType_DateTimePick)) {
            chidhWnd = XMLRES_创建日期框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"IPAddress") || !wcscmp(classname, zyType_IPAddress)) {
            chidhWnd = XMLRES_创建IP编辑框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"HotkeyBox") || !wcscmp(classname, zyType_Hotkey)) {
            chidhWnd = XMLRES_创建热键框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"LinkBox") || !wcscmp(classname, zyType_Link)) {
            chidhWnd = XMLRES_创建超链接框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"AnimateBox") || !wcscmp(classname, zyType_Animate)) {
            chidhWnd = XMLRES_创建影像框(parent ? parent : childhWnd, res, node);
        }
        else if (!wcscmp(classname, L"AlphaLabel") || !wcscmp(classname, zyType_TransparentLabel)) {
            chidhWnd = XMLRES_创建透明标签(parent ? parent : childhWnd, res, node);
        }
        else {
            //std::unique_ptr<zyCommandCtrol> ctrl(new zyCommandCtrol());
            zyCommandCtrol* p = new zyCommandCtrol();
            // 创建对象，并设置属性
            result = p->_CreateCtrol(parent ? parent : childhWnd, res.lpszName.c_str(), POINT{ res.x ,res.y }, POINT{ res.cx ,res.cy },
                res.id, res.style, res.ExStyle, classname);
            chidhWnd = p->getHwnd();
            //p->背景色(RGB(255, 0, 0));
            // 如果控件创建成功，则将其添加到资源管理中，否则释放内存
            if (result) 
                xml_AddControl(p, node);
            else
                delete p; // 确保在创建失败时释放内存
        }
        
    }
    return chidhWnd;
}

void* BlackMoonUI::zyXMLRes::xml_AddControl(zyWindow *child, pugi::xml_node node)
{
    //HWND hWndTop = GetAncestor(child->取窗口句柄(), GA_ROOT);// 获取控件的顶层窗口句柄
    //if(!hWndTop) return nullptr;
    //zyObject* pTop = zyEnv::getInstance().getWndObject(hWndTop); // 获取顶层窗口对象
    //if(!pTop) return nullptr;
   
    //zyObject* pControl = child->getObject();// 获取控件对象
    //if(!pControl)return nullptr;
    //
    //// 获取控件名称属性，如果为空则使用窗口句柄作为名称
    //std::wstring value = node.attribute(资源名_名称).value();
    //if(value.empty())
    //    value = std::to_wstring((int)(LONG_PTR)child->取窗口句柄());
    //pControl->setStringData(L"name",value);
    //std::unordered_map<std::wstring, LPVOID>* Controls = (std::unordered_map<std::wstring, LPVOID>*)pTop->getPtrData(L"Controls");
    //if (!Controls) {
    //    Controls = new std::unordered_map<std::wstring, LPVOID>();
    //    pTop->setPtrData(L"Controls", Controls);
    //}
    //// 如果顶层窗口对象中没有该名称的控件，则添加
    //if (Controls->find(value) == Controls->end()) {
    //    pControl->addRef();
    //    (*Controls)[value] = pControl;
    //    return pControl;
    //}

    std::wstring value = node.attribute(资源名_名称).value();
    if (value.empty()) {
        child->销毁();
        return nullptr;
    }
    zyObject* pControl = child->getObject();// 获取控件对象
    if (!pControl) {
        child->销毁();
        return nullptr;
    }
    pControl->setStringData(L"name", value);

    return pControl;// 如果已存在同名控件，则返回nullptr
}
bool BlackMoonUI::zyXMLRes::载入快捷键(const std::wstring& name, zyAccelTable& acc)
{
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//快捷键[@名称='" + name + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcerr << L"查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node menuNode = xpathNode.node();
    if (!menuNode) {
        std::wcout << L"节点 快捷键 获取失败!" << std::endl;
        return false;
    }
    std::vector<ACCEL> accInfos;
    ACCEL accInfo = {0};
    for (pugi::xml_node node1 : menuNode.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) { 
            accInfo.cmd = (short)node1.attribute(L"id").as_int(0);
            //std::wcout <<  L"  功能键状态: " << node1.attribute(L"功能键状态").value() << std::endl;
            accInfo.fVirt =node1.attribute(L"功能键状态").as_int(0);
            accInfo.key = (short)node1.attribute(L"键代码").as_int(0);
            accInfos.push_back(accInfo);
            //std::vector<ACCEL> accel_list{
            //	{ FALT | FVIRTKEY, 'C', 10003 },
            //};
            //accel.创建(accel_list);
        }
       
    }
    return acc.创建(accInfos);
}
bool BlackMoonUI::zyXMLRes::xml_LoadMenu(const std::wstring& name, zyMenu& menu)
{
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//菜单栏[@名称='" + name + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcerr << L"xml_LoadMenu查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node menuNode = xpathNode.node();
    //pugi::xml_node node2 = pnode->next_sibling(L"菜单栏");
    if (!menuNode) {
        std::wcout << L"节点 菜单栏 获取失败!" << std::endl;
        return false;
    }
    if(!menu.创建菜单栏())
       return false;
    xml_LoadMenuItem(menuNode, menu);
    return true;
}
bool BlackMoonUI::zyXMLRes::xml_LoadSubMenu(const std::wstring& name, zyMenu& menu)
{
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//子菜单[@名称='" + name + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcerr << L"查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node menuNode = xpathNode.node();
    //pugi::xml_node node2 = pnode->next_sibling(L"子菜单");
    if (!menuNode) {
        std::wcout << L"节点 子菜单 获取失败!" << std::endl;
        return false;
    }
    if (!menu.创建弹出菜单())
        return false;
    xml_LoadMenuItem(menuNode, menu);
    return true;
}
void BlackMoonUI::zyXMLRes::xml_LoadMenuItem(pugi::xml_node node, zyMenu& menuParent) {
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            //std::wcout << L"  项目: " << node1.attribute(L"标题").value() << std::endl;
            int id = node1.attribute(L"id").as_int(0);
            menuParent.添加项目(node1.attribute(L"标题").value(), id);
        }
        else if (!wcscmp(name1, L"子菜单")) {
            //std::wcout << L"  子菜单: " << node1.attribute(L"标题").value() << std::endl;
            zyMenu subMenu;
            subMenu.创建弹出菜单();
            if (node1.first_child()) {
                xml_LoadMenuItem(node1, subMenu);
            }
            menuParent.添加弹出菜单(subMenu, node1.attribute(L"标题").value());
        }
        else if (!wcscmp(name1, L"分割线")) {
            menuParent.添加分割线();
        }
        
    }
}
bool BlackMoonUI::zyXMLRes::xml_LoadImageList(const std::wstring& name, zyLmageList& imageList)
{
    pugi::xml_document* xmlDoc = reinterpret_cast<pugi::xml_document*>(GetMember());
    // 构造 XPath 查询字符串
    std::wstring xpathQuery = L"//图片组[@名称='" + name + L"']";

    // 使用 XPath 查询节点
    pugi::xpath_node xpathNode = xmlDoc->select_node(xpathQuery.c_str());
    if (!xpathNode) {
        std::wcerr << L"查询资源名: " << name << L" 失败！" << xpathQuery << std::endl;
        return false; // 如果节点未找到，返回失败
    }
    // 获取查询到的节点
    pugi::xml_node menuNode = xpathNode.node();
    //pugi::xml_node node2 = pnode->next_sibling(L"菜单栏");
    if (!menuNode) {
        std::wcout << L"节点 图片组 获取失败!" << std::endl;
        return false;
    }
    bool pVal = menuNode.attribute(L"易格式").as_bool();
    // 获取CDATA部分的内容
    std::wstring base64Data = menuNode.child_value();
    if(base64Data.empty())return false;
    std::vector<BYTE> output = zybase64_decode(base64Data.c_str());


    return imageList.创建自字节集(output.data(), (int)output.size(), pVal);
}
bool BlackMoonUI::zyXMLRes::xml_GetIcon(const std::wstring& value, zyIcon& icon)
{
    //std::wcout <<  L" 图标 value: " << value << std::endl;
    std::wstring 局部_前缀, 局部_值;
    int pos = (int)value.find(L":");
    if (pos == -1) {
        局部_前缀 = L"文件名";
        局部_值 = value;
    }
    else {
        局部_前缀 = value.substr(0, pos);
        局部_值 = value.substr(value.length() - pos - 1, pos);
    }

    if (!wcscmp(局部_前缀.c_str(), L"文件名"))
        return icon.载入文件(value);
    else if (!wcscmp(局部_前缀.c_str(), L"资源名")) {
        // 构造 XPath 查询字符串
        std::wstring xpathQuery = L"//图标[@name='" + 局部_值 + L"']";
    }
    else if (!wcscmp(局部_前缀.c_str(), L"系统")) {
        std::wstringstream wss(value);
        int num;
        wss >> num; // 从宽字符串流中提取整数
        return icon.载入系统图标(num);
    }
    return false;
}

void BlackMoonUI::zyXMLRes::xml_GetCtrolCreateStruct(pugi::xml_node node, XmlResCreateStruct& xrcs) const
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        /*if (!wcscmp(name, 资源名_矩形)) {
            RECT objRect = zyStringToRECT(attr.value());
            xrcs.x = objRect.left;
            xrcs.y = objRect.top;
            xrcs.cx = objRect.right;
            xrcs.cy = objRect.bottom;
            xrcs.flages = xrcs.flages | XRF_rect;
        }*/
        if (!wcscmp(name, 资源名_左边)) {
            xrcs.x = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_x;
        }
        else if (!wcscmp(name, 资源名_顶边)) {
            xrcs.y = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_y;
        }
        else if (!wcscmp(name, 资源名_宽度)) {
            xrcs.cx = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_cx;
        }
        else if (!wcscmp(name, 资源名_高度)) {
            xrcs.cy = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_cy;
        }
        else if (!wcscmp(name, 资源名_窗口风格)) {
            xrcs.style = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_style;
        }
        else if (!wcscmp(name, 资源名_扩展风格)) {
            xrcs.ExStyle = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_exStyle;
        }
        else if (!wcscmp(name, 资源名_ID)) {
            xrcs.id = attr.as_int();
            xrcs.flages = xrcs.flages | XRF_id;
        }
        else if (!wcscmp(name, 资源名_标题)) {
            xrcs.lpszName = attr.value();
            xrcs.flages = xrcs.flages | XRF_name;
        }
    }
}
void BlackMoonUI::zyXMLRes::XMLRES_置基本属性(zyWindow* form, pugi::xml_node* root) {
    for (pugi::xml_attribute attr = root->first_attribute(); attr; attr = attr.next_attribute()) {
        const wchar_t* name = attr.name();
        if (wcscmp(name, 资源名_禁止) == 0) {
            form->禁止(attr.as_bool());
        }
        else if (!wcscmp(name, 资源名_可视)) {
            form->可视(attr.as_bool());
        }
        
    }
}
void BlackMoonUI::zyXMLRes::XMLRES_置按钮属性(zyButton * pbtn, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"默认按钮")) {
            pbtn->默认按钮(attr.as_bool());
        }
        else if (!wcscmp(name, L"取消按钮")) {
            pbtn->取消按钮(attr.as_bool());
        }
        else if (!wcscmp(name, 资源名_背景色)) {
            pbtn->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            pbtn->文本色(attr.as_int());
        }
    }
}
void BlackMoonUI::zyXMLRes::XMLRES_置控件属性(zyWindow* contorl, pugi::xml_node hNode) {//所有控件属性
    XMLRES_置基本属性(contorl, &hNode);
    zyIcon cursor;
    //std::vector<wchar_t*> fontVals;
    int pVal = hNode.attribute(资源名_鼠标指针).as_int();
    //pVal = XmlNode_GetAttributeValueA_Ptr(hNode, 资源名_鼠标指针);
    //if (pVal != 0) {
    //    value = 指针到文本W(pVal);
    //    if (xmlres_Getcursor(hNode, value, cursor)) {
    //        contorl->置鼠标指针(cursor);
    //    }
    //}
    //pVal = hNode.attribute(资源名_字体).as_int();
    //if (pVal != 0) {
    //    zyStr.添加文本指针W(pVal);
    //    count = zyStr.分割文本(",", fontVals, 1)  // 空格分隔;
    //        oldFont = contorl.取字体();
    //    if(count == 1)  // 只有字体名;
    //        newFont.创建自名称(fontVals[1], oldFont.取尺寸(), 0, 单位_点);
    //    else if(count == 2)  // 名称 和 尺寸;
    //        newFont.创建自名称(fontVals[1], 到小数(fontVals[2]), 0, 单位_点);
    //    else if (count == 3)  // 名称 、 尺寸 和 风格;
    //        newFont.创建自名称(fontVals[1], 到小数(fontVals[2]), 到整数(fontVals[3]), 单位_点);
    //    newFont = oldFont;
    //    contorl->置字体(newFont);
    //}
    pVal = hNode.attribute(资源名_边框).as_int();
    if (pVal != 0) {
        contorl->边框(pVal);
    }
    pVal = hNode.attribute(资源名_ZY窗口风格).as_int();
    if (pVal != 0) {
        contorl->移除ZY窗口风格(ZY窗口风格_需要TAB键 | ZY窗口风格_需要回车键 | 4);//ZY窗口风格_需要方向键=4
        contorl->添加ZY窗口风格(pVal);
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建按钮(HWND parent, XmlResCreateStruct &xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0){
        xrcs.lpszName = L"按钮";
    }
    if ((xrcs.flages & XRF_cx) == 0){
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 32;
    }
    if ((xrcs.flages & XRF_id) == 0){
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0){
        xrcs.style = WS_TABSTOP;
    }
    zyButton* button = new zyButton();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置按钮属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建编辑框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"编辑框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 20;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = ES_AUTOHSCROLL | WS_TABSTOP;
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.ExStyle = WS_EX_CLIENTEDGE;
    }
    bool pVal = hNode.attribute(L"多行").as_bool();
    if (pVal) {
        xrcs.style = WS_TABSTOP;
        xrcs.style = xrcs.style | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL;
        bool 换行 = hNode.attribute(L"自动换行").as_bool();
        if (换行) {
            xrcs.style = xrcs.style | WS_VSCROLL;
        }else
            xrcs.style = xrcs.style | WS_HSCROLL | WS_VSCROLL;
    }
    else {
        xrcs.style = WS_TABSTOP;
        xrcs.style = xrcs.style | ES_AUTOHSCROLL ;
    }
    pVal = hNode.attribute(L"密码输入").as_bool();
    if (pVal)
        xrcs.style = xrcs.style | ES_NUMBER;
    else
        xrcs.style = xrcs.style & (~ES_NUMBER);
    pVal = hNode.attribute(L"隐藏选择").as_bool();
    if (pVal)
        xrcs.style = xrcs.style | ES_NOHIDESEL;
    else
        xrcs.style = xrcs.style & (~ES_NOHIDESEL);
    zyEditBox* p = new zyEditBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置编辑框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置编辑框属性(zyEditBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"只读")) {
            ptr->置只读属性(attr.as_bool());
        }
        else if (!wcscmp(name, L"最大长度")) {
            ptr->最大长度(attr.as_int());
        }
        else if (!wcscmp(name, L"垂直居中")) {
            ptr->垂直居中(attr.as_bool());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建分组框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"分组框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 120;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 100;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    zyGroupBox* p = new zyGroupBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置分组框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置分组框属性(zyGroupBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建单选框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"单选框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 32;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    zyRadioBox* p = new zyRadioBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置单选框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置单选框属性(zyRadioBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"check")) {
            ptr->SetSel(attr.as_bool());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建选择框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"选择框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 32;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    zyCheckBox* p = new zyCheckBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置选择框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置选择框属性(zyCheckBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"check")) {
            ptr->SetSel(attr.as_bool());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建标签(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"标签";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 32;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = SS_CENTERIMAGE;
    }
    zyStatic* p = new zyStatic();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置标签属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置标签属性(zyStatic* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建组合框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"组合框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = CBS_DROPDOWN | CBS_AUTOHSCROLL;
    }
    bool pVal = hNode.attribute(L"禁止编辑").as_bool();
    if (pVal) {
        xrcs.style &= ~3;
        xrcs.style |= CBS_DROPDOWNLIST;
    }
    else{
        xrcs.style &= ~3;
        xrcs.style |= CBS_DROPDOWN;
    }

    zyComboBox* p = new zyComboBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置组合框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置组合框属性(zyComboBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
    }
    int selected = -1;
    int i = 0;
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            int lparam = node1.attribute(L"项目数值").as_int(0);
            selected = node1.attribute(L"选择").as_int(0);
            if (selected != 0)
                selected = i;
            ptr->加入项目(text, lparam);
        }
        i++;
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置组合框属性(ptr, node);
        }
    }
    if(selected != -1)
        ptr->置现行选中项(selected);
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建列表框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"列表框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 120;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = LBS_USETABSTOPS | WS_VSCROLL | WS_TABSTOP | WS_HSCROLL | LBS_NOINTEGRALHEIGHT;
    }
    if ((xrcs.flages & XRF_exStyle) == 0)
        xrcs.ExStyle = WS_EX_CLIENTEDGE;
    bool pVal = hNode.attribute(L"多选").as_bool();
    if (pVal) {
        xrcs.style |= LBS_EXTENDEDSEL;
    }
    zyListBox* p = new zyListBox();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置列表框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置列表框属性(zyListBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"项目高度")) {
            ptr->置项目高度(attr.as_int());
        }
    }
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            int lparam = node1.attribute(L"项目数值").as_int(0);
            ptr->加入项目(text, lparam);
        }
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置列表框属性(ptr, node);
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建滚动条(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    bool pVal = hNode.attribute(L"垂直").as_bool();
    if (pVal) {
        xrcs.style |= SBS_VERT;
    }else {
        xrcs.style |= SBS_HORZ;
    }
    zyScrollBar* button = new zyScrollBar();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置滚动条属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置滚动条属性(zyScrollBar* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"位置")) {
            ptr->位置(attr.as_int());
        }
        else if (!wcscmp(name, L"行改变值")) {
            ptr->行改变值(attr.as_int());
        }
        else if (!wcscmp(name, L"页改变值")) {
            ptr->页改变值(attr.as_int());
        }
        else if (!wcscmp(name, L"最大位置")) {
            ptr->最大位置(attr.as_int());
        }
        else if (!wcscmp(name, L"最小位置")) {
            ptr->最小位置(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建图片框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 80;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    zyPictureBox* button = new zyPictureBox();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置图片框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置图片框属性(zyPictureBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"background-image")) {
            ptr->图片(attr.value());
        }
        else if (!wcscmp(name, L"图片显示方式")) {
            ptr->图片显示方式(attr.as_int());
        }
        else if (!wcscmp(name, L"播放动画")) {
            ptr->播放动画(attr.as_bool());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建树型框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"TreeView";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 120;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 160;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = WS_VSCROLL | WS_HSCROLL;
    }
    if ((xrcs.flages & XRF_exStyle) == 0)
        xrcs.ExStyle = WS_EX_CLIENTEDGE;
    
    if (hNode.attribute(L"显示连线").as_bool()) {
        xrcs.style |= TVS_HASLINES;
    }
    if (hNode.attribute(L"显示根部线").as_bool()) {
        xrcs.style |= TVS_LINESATROOT;
    }
    if (hNode.attribute(L"显示加减框").as_bool()) {
        xrcs.style |= TVS_HASBUTTONS;
    }
    zyTreeView* p = new zyTreeView();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        //std::wcout << p->加入项目((INT_PTR)0, L"text", 0, 0, 0, 0) << std::endl;
        XMLRES_置树型框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置树型框属性(zyTreeView* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"连线色")) {
            ptr->连线色(attr.as_int());
        }
        else if (!wcscmp(name, L"缩进距离")) {
            ptr->缩进距离(attr.as_int());
        }
        else if (!wcscmp(name, L"项目高度")) {
            ptr->项目高度(attr.as_int());
        }
        else if (!wcscmp(name, L"图片组")) {
            zyLmageList ImgList;
            if(xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList, TVSIL_NORMAL);
        }
        else if (!wcscmp(name, L"图片组状态")) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList, TVSIL_STATE);
        }
    }
    XMLRES_树型框加入项目(ptr, node,0);
}
void BlackMoonUI::zyXMLRes::XMLRES_树型框加入项目(zyTreeView* ptr, pugi::xml_node node, HTREEITEM treeNode) {
    
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        HTREEITEM hInsertAfter = 0;
        TVINSERTSTRUCT TVIS = { 0 };
        if (!wcscmp(name1, L"项目")) {            
            TVIS.item.mask = TVIF_TEXT | TVIF_PARAM;
            TVIS.item.iImage = -1;
            TVIS.item.iSelectedImage = -1;
            TVIS.hParent = treeNode ? treeNode : 0;
            TVIS.hInsertAfter = TVI_LAST;           

           /* for (pugi::xml_attribute attr : node1.attributes()) {
                const wchar_t* name = attr.name();
                if (!wcscmp(name, 资源名_标题)) {
                    std::wstring text = attr.value();
                    TVIS.item.pszText = (LPWSTR)text.c_str();
                    TVIS.item.cchTextMax = (int)text.size() + 1;
                }
                else if (!wcscmp(name, L"项目数值")) {
                    TVIS.item.lParam = attr.as_int();
                }

            }*/

            std::wstring text = node1.attribute(资源名_标题).value();
            if (!text.empty()) {
                TVIS.item.pszText = (LPWSTR)text.c_str();
                TVIS.item.cchTextMax = (int)text.size() + 1;
            }

            TVIS.item.lParam = node1.attribute(L"项目数值").as_int(0);

            TVIS.item.iImage = node1.attribute(L"图片索引").as_int(0);
            if (TVIS.item.iImage >= 0) {
                TVIS.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
                TVIS.item.iSelectedImage = TVIS.item.iImage;
            }
            TVIS.item.iSelectedImage = node1.attribute(L"选择图片索引").as_int(0);

            hInsertAfter = (HTREEITEM)ptr->发送消息(TVM_INSERTITEMW, 0, (LPARAM)&TVIS);
            if (hInsertAfter == NULL) {
                std::wcout << L"插入项目失败" << std::endl;
                continue;
            }
           
        }      
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_树型框加入项目(ptr, node1, hInsertAfter);
        }
    }
    std::wstring text = node.attribute(L"扩展").value();
    if (!text.empty()) {
        ptr->扩展(treeNode);
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建工具条(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = TBSTYLE_FLAT | CCS_TOP | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | CCS_NODIVIDER;
    }
    if (hNode.attribute(L"显示连线").as_bool()) {
        xrcs.style |= TVS_HASLINES;
    }

    zyToolBar* p = new zyToolBar();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        //std::wcout << p->加入项目((INT_PTR)0, L"text", 0, 0, 0, 0) << std::endl;
        XMLRES_置工具条属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置工具条属性(zyToolBar* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图显示方式)) {
            ptr->背景图显示方式(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图)) {
            //ptr->背景图(attr.as_int());
        }
        else if (!wcscmp(name, L"缩进")) {
            ptr->置缩进(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_图片组)) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList, 工具条图片组_通常);
        }
        else if (!wcscmp(name, L"图片组点燃")) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList, 工具条图片组_点燃);
        }
        else if (!wcscmp(name, L"图片组禁止")) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList, 工具条图片组_禁止);
        }
    }

    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            int lparam = node1.attribute(L"类型").as_int(-1);
            int 图片索引 = node1.attribute(L"图片索引").as_int(-1);
            int id = node1.attribute(资源名_ID).as_int(-1);
            if (id == -1)
                id = 黑月默认ID();
            std::wstring value = node1.attribute(L"提示文本").value();
            int i = node1.attribute(L"状态").as_int(-1);
            ptr->插入按钮(-1, id,text, lparam, 图片索引, value,i);
        }

        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置工具条属性(ptr, node);
        }
    }

}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建调节器(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 22;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        
        xrcs.style = UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS;
    }
    bool pVal = hNode.attribute(L"水平").as_bool();
    if (pVal) {
        xrcs.style |= UDS_HORZ;
    }
    else {
        xrcs.style &= ~UDS_HORZ;
    }

    zyUpDown* p = new zyUpDown();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置调节器属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置调节器属性(zyUpDown* ptr, pugi::xml_node node)
{
    POINT pt = ptr->取按钮值范围();
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"按钮值")) {
            ptr->按钮值(attr.as_int());
        }
        else if (!wcscmp(name, L"基数")) {
            ptr->基数(attr.as_int());
        }
        else if (!wcscmp(name, L"最大值")) {
            pt.y = attr.as_int();
        }
        else if (!wcscmp(name, L"最小值")) {
            pt.x = attr.as_int();
        }
        else if (!wcscmp(name, L"关联编辑框")) {
            //黑月取根窗口();


            HWND hWndTop = GetAncestor(ptr->取窗口句柄(), GA_ROOT);
            if (IsWindow(hWndTop) != 0)
            {
                zyObject* Ptr = zyEnv::getInstance().getWndObject(hWndTop);
                if (Ptr != nullptr) {
                    zyWidget* Ptr2 = (zyWidget*)&Ptr;
                    
                    zyObject* obj =  Ptr2->取资源控件(attr.value());
                    ptr->关联控件((zyWindow*)&obj);

                    //auto controlsPtr = Ptr->getPtrData(L"Controls");
                    //auto* controls = (std::unordered_map<std::wstring, LPVOID>*)(controlsPtr);
                    //if (!controls) {
                    //    return ;
                    //}
                    //// 检查参数是否为空或包含非法字符
                    //if (!attr.value()) {
                    //    return ;
                    //}
                    //// 查找资源控件
                    //auto it = controls->find(attr.value());
                    //if (it != controls->end()) {
                    //    ptr->关联控件(static_cast<zyWindow*>(it->second));
                    //}
                }
            }          
        }
    }
    ptr->置按钮值范围(pt.x, pt.y);
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建选择夹(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 180;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 200;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = TCS_TOOLTIPS;
    }
    zyTabControl* p = new zyTabControl();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置选择夹属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置选择夹属性(zyTabControl* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图显示方式)) {
            //ptr->背景图显示方式(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图)) {
            //ptr->背景图(attr.as_int());
        }
        else if (!wcscmp(name, L"隐藏自身")) {
            ptr->隐藏自身(attr.as_bool());
        }
        else if (!wcscmp(name, 资源名_图片组)) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList);
        }
    }

    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, zyType_Panel)) {
            std::wstring text = node1.attribute(资源名_标题).value();
            int 图片索引 = node1.attribute(L"图片索引").as_int(-1);
            std::wstring value = node1.attribute(L"提示文本").value();
            XmlResCreateStruct xrcs = {0};
            xml_GetCtrolCreateStruct(node1, xrcs);
            //std::vector<zyPanel*>* 面板 = (std::vector<zyPanel*>*)ptr->GetMember(L"zyPanels");
            //if (!面板) {
             //   面板 = new std::vector<zyPanel*>(); // 显式清空（非必须）
                // 或添加元素：面板.push_back(new zyPanel(...));
            //    ptr->SetMember(L"zyPanels",(LONG_PTR)面板);
           // }
            zyPanel* pControl = XMLRES_创建面板(ptr->getHwnd(), xrcs, node1);
            if (pControl) {
                //面板->push_back(pControl);               
                ptr->添加子夹(pControl, text, 图片索引, value);
                //XMLRES_CreateControl(node1.first_child(), pControl->getHwnd());
                xml_ParseNodeCreateControl(&node1, pControl->getHwnd(), NULL);
            }  
        }
        else
        {
            continue;// 跳过当前节点，继续解析下一个节点。因为可能有列表框的子节点，这里不需要解析。
        }
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置选择夹属性(ptr, node1);
        }
    }
}
BlackMoonUI::zyPanel* BlackMoonUI::zyXMLRes::XMLRES_创建面板(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 200;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 200;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = WS_VISIBLE;
    }
    // 使用智能指针管理 zyPanel 对象
    std::unique_ptr<zyPanel> p(new zyPanel());
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p.get(), hNode);
        XMLRES_置面板属性(p.get(), hNode);
        xml_AddControl(p.get(), hNode);
    }
    return p.release();
}
void BlackMoonUI::zyXMLRes::XMLRES_置面板属性(zyPanel* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"background-image")) {
            //ptr->背景图(attr.value());
        }
        else if (!wcscmp(name, L"背景图显示方式")) {
            ptr->背景图显示方式(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建状态栏(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 200;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = SBARS_SIZEGRIP | CCS_BOTTOM | CCS_NOMOVEY;
    }
    bool pVal = hNode.attribute(L"尺寸调节器").as_bool();
    if (pVal)
        xrcs.style = xrcs.style | SBARS_SIZEGRIP;
    else
        xrcs.style = xrcs.style & (~SBARS_SIZEGRIP);

    zyStatusBar* p = new zyStatusBar();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置状态栏属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p;
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置状态栏属性(zyStatusBar* ptr, pugi::xml_node node)
{
    zyLmageList ImgList;
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->置背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"简单模式")) {
            ptr->置简单模式(attr.as_bool());
        }
        else if (!wcscmp(name, L"最小高度")) {
            ptr->置最小高度(attr.as_int());
        }
        else if (!wcscmp(name, L"图片组")) {
            
            if (xml_LoadImageList(attr.value(), ImgList)) {
                //std::wcout << L"置状态栏属性:图片组加载成功" << std::endl;
                
            }
                
        }
    }
    std::vector<int> widths;
    std::vector<StatusBarItem> items;
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {

            std::wstring text = node1.attribute(资源名_标题).value();

            std::wstring lparam = node1.attribute(资源名_图标).value();

            std::wstring value = node1.attribute(L"提示文本").value();

            StatusBarItem sbt;
            //std::wcout << ImgList.取图标(4,0).getIcon() << std::endl;
            //zyIcon* 图标 =new zyIcon();
            //if (xml_GetIcon(lparam, *图标)) {
            //    sbt.图标 = 图标;
            //}
            //else{
            //    sbt.图标 = 图标;
            //}
            sbt.图片索引 = node1.attribute(L"图片索引").as_int(-1);
            sbt.标题 = text;
            sbt.提示文本 = value;
            items.push_back(sbt);
            widths.push_back(node1.attribute(L"宽度").as_int(-1));
            //delete 图标;
        }
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置状态栏属性(ptr, node);
        }
    }

    ptr->分割栏目(widths);
    for (int i = 0; i < items.size(); i++) {
        ptr->置栏目文本(i, items[i].标题);
        ptr->置动态提示文本(i,items[i].提示文本);
        if (items[i].图片索引 != -1) {
            zyIcon ico = ImgList.取图标(items[i].图片索引, 0);
            ptr->置栏目图标(i, ico);
        }

    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建进度条(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    bool pVal = hNode.attribute(L"垂直").as_bool();
    if (pVal) {
        xrcs.style |= PBS_VERTICAL;
    }
    else {
        xrcs.style &= ~PBS_VERTICAL;
    }
    pVal = hNode.attribute(L"连续").as_bool();
    if (pVal) {
        xrcs.style |= PBS_SMOOTH;
    }
    else {
        xrcs.style &= ~PBS_SMOOTH;
    }
    zyProgressBar* button = new zyProgressBar();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置进度条属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置进度条属性(zyProgressBar* ptr, pugi::xml_node node)
{
    POINT rang = ptr->取范围();
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->置背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"位置")) {
            ptr->位置(attr.as_int());
        }
        else if (!wcscmp(name, L"跨度值")) {
            ptr->置跨度值(attr.as_int());
        }
        else if (!wcscmp(name, L"前景色")) {
            ptr->置前景色(attr.as_int());
        }
        else if (!wcscmp(name, L"最大位置")) {
            rang.y = attr.as_int();
        }
        else if (!wcscmp(name, L"最小位置")) {
            rang.x = attr.as_int();
        }
    }
    ptr->置范围(rang.x,rang.y);
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建滑块条(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = TBS_AUTOTICKS | TBS_TOOLTIPS;
    }
    bool pVal = hNode.attribute(L"垂直").as_bool();
    if (pVal) {
        xrcs.style |= TBS_VERT;
    }
    else {
        xrcs.style |= TBS_HORZ;
    }
    zyTrackBar* button = new zyTrackBar();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置滑块条属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置滑块条属性(zyTrackBar* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"位置")) {
            ptr->位置(attr.as_int());
        }
        else if (!wcscmp(name, L"跨度值")) {
            ptr->滑块跨度(attr.as_int());
        }
        else if (!wcscmp(name, L"行改变值")) {
            ptr->行改变值(attr.as_int());
        }
        else if (!wcscmp(name, L"页改变值")) {
            ptr->页改变值(attr.as_int());
        }
        else if (!wcscmp(name, L"最大位置")) {
            ptr->最大位置(attr.as_int());
        }
        else if (!wcscmp(name, L"最小位置")) {
            ptr->最小位置(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建超级列表框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 280;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 200;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }

    bool pVal = hNode.attribute(L"平面列头").as_bool();
    if (pVal) {
        xrcs.style |= LVS_NOSORTHEADER;
    }
    else {
        xrcs.style &= ~LVS_NOSORTHEADER;
    }

    zyListView* p = new zyListView();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置超级列表框属性(p, hNode);
        xml_AddControl(p, hNode);
        p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置超级列表框属性(zyListView* ptr, pugi::xml_node node)
{
    // 处理节点属性
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int(),1);
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, L"显示类型")) {
            ptr->置显示类型(attr.as_int());
        }
        else if (!wcscmp(name, L"单一选择")) {
            attr.as_bool() ? ptr->AddStyle(LVS_SINGLESEL) : ptr->RemoveStyle(LVS_SINGLESEL);
        }
        else if (!wcscmp(name, L"始终显示选择项")) {
            attr.as_bool() ? ptr->AddStyle(LVS_SHOWSELALWAYS) : ptr->RemoveStyle(LVS_SHOWSELALWAYS);
        }
        else if (!wcscmp(name, L"自动排列")) {
            attr.as_bool() ? ptr->AddStyle(LVS_AUTOARRANGE) : ptr->RemoveStyle(LVS_AUTOARRANGE);
        }
        else if (!wcscmp(name, L"允许编辑")) {
            attr.as_bool() ? ptr->AddStyle(LVS_EDITLABELS) : ptr->RemoveStyle(LVS_EDITLABELS);
        }
        else if (!wcscmp(name, L"无表头")) {
            attr.as_bool() ? ptr->AddStyle(LVS_NOCOLUMNHEADER) : ptr->RemoveStyle(LVS_NOCOLUMNHEADER);
        }
        else if (!wcscmp(name, L"显示表格线")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_GRIDLINES) : ptr->移除超列扩展风格(LVS_EX_GRIDLINES);
        }
        else if (!wcscmp(name, L"显示检查框")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_CHECKBOXES) : ptr->移除超列扩展风格(LVS_EX_CHECKBOXES);
        }
        else if (!wcscmp(name, L"热点跟踪")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_TRACKSELECT) : ptr->移除超列扩展风格(LVS_EX_TRACKSELECT);
        }
        else if (!wcscmp(name, L"表头可拖动")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_HEADERDRAGDROP) : ptr->移除超列扩展风格(LVS_EX_HEADERDRAGDROP);
        }
        else if (!wcscmp(name, L"整行选择")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_FULLROWSELECT) : ptr->移除超列扩展风格(LVS_EX_FULLROWSELECT);
        }
        else if (!wcscmp(name, L"单击激活")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_ONECLICKACTIVATE) : ptr->移除超列扩展风格(LVS_EX_ONECLICKACTIVATE);
        }
        else if (!wcscmp(name, L"双击激活")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_TWOCLICKACTIVATE) : ptr->移除超列扩展风格(LVS_EX_TWOCLICKACTIVATE);
        }
        else if (!wcscmp(name, L"对齐到网格")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_SNAPTOGRID) : ptr->移除超列扩展风格(LVS_EX_SNAPTOGRID);
        }
        else if (!wcscmp(name, L"简单选择")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_SIMPLESELECT) : ptr->移除超列扩展风格(LVS_EX_SIMPLESELECT);
        }
        else if (!wcscmp(name, L"工具提示")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_LABELTIP) : ptr->移除超列扩展风格(LVS_EX_LABELTIP);
        }
        else if (!wcscmp(name, L"隐藏标题")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_HIDELABELS) : ptr->移除超列扩展风格(LVS_EX_HIDELABELS);
        }
        else if (!wcscmp(name, L"双缓冲")) {
            attr.as_bool() ? ptr->添加超列扩展风格(LVS_EX_DOUBLEBUFFER) : ptr->移除超列扩展风格(LVS_EX_DOUBLEBUFFER);
        }
        else if (!wcscmp(name, L"文本背景色")) {
            ptr->文本背景色(attr.as_int());
        }
    }
    
    // 处理子节点
    int iGroupId = 0;
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"列")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            LVCOLUMN column = { 0 };
            column.mask |= LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
            column.cx = node1.attribute(L"宽度").as_int(0);
            column.pszText = (LPWSTR)text.c_str();
            column.cchTextMax = (int)text.size();
            column.fmt = node1.attribute(L"对齐方式").as_int(0);
            column.fmt |= node1.attribute(L"图片居右").as_int(0);
            column.iImage = node1.attribute(L"图片索引").as_int(-1);
            if(column.iImage != -1)
                column.mask |= LVCF_IMAGE;

            int columnCount = ptr->取列数();
            int index = (int)ptr->发送消息(LVM_INSERTCOLUMNW, columnCount, (LPARAM)&column);

        }else if(!wcscmp(name1, L"项目")) {
            XMLRES_超级列表框插入表项(ptr, node1, 0);
        }
        else if (!wcscmp(name1, L"分组")) {
            if (iGroupId == 0)
                ptr->启用分组(true);
            
            LVGROUP lvg = { 0 };
            lvg.cbSize = sizeof(LVGROUP);
            lvg.mask |= LVGF_GROUPID | LVGF_HEADER | LVGF_FOOTER | LVGF_ALIGN | LVGF_STATE;
            lvg.iGroupId = iGroupId + 1;
            std::wstring text = node1.attribute(资源名_标题).value();
            if (!text.empty()) {
                lvg.pszHeader = (LPWSTR)text.c_str();
                lvg.cchHeader = (int)text.size();
            }
            std::wstring text1 = node1.attribute(L"页脚标题").value();
            if (!text1.empty()) {
                lvg.pszFooter = (LPWSTR)text1.c_str();
                lvg.cchFooter = (int)text1.size();
            }
            lvg.uAlign = node1.attribute(L"对齐方式").as_int(0);
            lvg.state = node1.attribute(L"状态").as_int(0);
            lvg.stateMask = lvg.state;

            if (ptr->发送消息(LVM_INSERTGROUP, -1, (LPARAM)&lvg) == -1)
                continue;
            
            for (pugi::xml_node child : node1.children()) {
                XMLRES_超级列表框插入表项(ptr, child, lvg.iGroupId);
            }
            //pugi::xml_node node2 = node1.first_child();
            //if (node2.first_child()) {
            //    do {
           //         XMLRES_超级列表框插入表项(ptr, node2, iGroupId);
           //     } while (node2 = node2.next_sibling());
           // }
            iGroupId = iGroupId + 1;
        }

        // 递归处理同级节点
        if (node1.next_sibling()) {
            XMLRES_置超级列表框属性(ptr, node1);
        }
       
    }
}
int BlackMoonUI::zyXMLRes::XMLRES_超级列表框插入表项(zyListView* ptr, pugi::xml_node node, int iGroupId) {
    LVITEM item = { 0 };
    item.mask |= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE | LVIF_INDENT;
    item.iItem = ptr->取表项数();
    item.iSubItem = 0;
    item.state = node.attribute(L"状态图片索引").as_int();
    item.stateMask = LVIS_STATEIMAGEMASK;
    std::wstring text = node.attribute(资源名_标题).value();
    item.pszText = (LPWSTR)text.c_str();
    item.cchTextMax = (int)text.size();
    item.iImage = node.attribute(L"图片索引").as_int(-1);
    item.lParam = node.attribute(L"项目数值").as_int();
    item.iIndent = node.attribute(L"缩进数目").as_int();
    item.iGroupId = iGroupId;
    if (item.iGroupId > 0)
        item.mask |= LVIF_GROUPID;
    int index = (int)ptr->发送消息(LVM_INSERTITEMW, 0, (LPARAM)&item);
    if (index == -1)
        return index;

    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"子项目")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            ptr->置标题(index, 1, text);
        }
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_超级列表框插入表项(ptr, node1, iGroupId);
        }
    }
    return index;
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建外形框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 80;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = SS_BLACKRECT;
    }
    zyShapeBox* button = new zyShapeBox();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置外形框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置外形框属性(zyShapeBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建选择框三态(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = WS_TABSTOP;
    }
    zyCheckB3State* button = new zyCheckB3State();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置选择框三态属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置选择框三态属性(zyCheckB3State* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        if (!wcscmp(name, L"check")) {
            ptr->置状态(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建图像组合框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"图像组合框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = CBS_DROPDOWN | WS_TABSTOP | CBS_AUTOHSCROLL | WS_VSCROLL;
    }
    bool pVal = hNode.attribute(L"禁止编辑").as_bool();
    if (pVal) {
        xrcs.style &= ~3;
        xrcs.style |= CBS_DROPDOWNLIST;
    }
    else {
        xrcs.style &= ~3;
        xrcs.style |= CBS_DROPDOWN;
    }

    zyComboBoxEx* p = new zyComboBoxEx();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(p, hNode);
        XMLRES_置图像组合框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置图像组合框属性(zyComboBoxEx* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_图片组)) {
            zyLmageList ImgList;
            if (xml_LoadImageList(attr.value(), ImgList))
                ptr->置图片组(ImgList);
        }
    }
    int selected = -1;
    int i = 0;
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            COMBOBOXEXITEM cbex = { 0 };
            cbex.mask |= CBEIF_TEXT | CBEIF_LPARAM | CBEIF_DI_SETITEM;
            cbex.iItem = -1;
            std::wstring text = node1.attribute(资源名_标题).value();
            cbex.pszText = (LPWSTR)text.c_str();
            cbex.cchTextMax = (int)text.size();
            int iImage = node1.attribute(L"图片索引").as_int(-1);
            if (iImage != -1) {
                cbex.iImage = iImage;
                cbex.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
                cbex.iSelectedImage = iImage;
            }
            iImage = node1.attribute(L"选中图片索引").as_int(-1);
            if (iImage != -1) {
                cbex.mask |= CBEIF_SELECTEDIMAGE;
                cbex.iSelectedImage = iImage;
            }
            iImage = node1.attribute(L"覆盖图片索引").as_int(-1);
            if (iImage != -1) {
                cbex.mask |= CBEIF_OVERLAY;
                cbex.iOverlay = iImage;
            }
            iImage = node1.attribute(L"缩进距离").as_int(0);
            if (iImage) {
                cbex.mask |= CBEIF_INDENT;
                cbex.iIndent = iImage;
            }
            cbex.lParam = node1.attribute(L"项目数值").as_int(0);
            selected = node1.attribute(L"选择").as_int(0);
            if (selected != 0)
                selected = i;
            ptr->发送消息(CBEM_INSERTITEMW,0, (LPARAM)&cbex);
        }
        i++;
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置图像组合框属性(ptr, node);
        }
    }
    if (selected != -1)
        ptr->置现行选中项(selected);
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建选择列表框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"选择列表框";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 180;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 100;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = LBS_USETABSTOPS | WS_VSCROLL | WS_TABSTOP;
    }

    bool pVal = hNode.attribute(L"多选").as_bool();
    if (pVal) {
        xrcs.style |= LBS_EXTENDEDSEL;
    }
    
    zyListBoxEx* p = new zyListBoxEx();
    bool result = p->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        pugi::xml_attribute attributeValue = hNode.attribute(资源名_图片组);
        if (attributeValue && !wcscmp(attributeValue.name(), 资源名_图片组)){
            zyLmageList ImgList;
            if (xml_LoadImageList(attributeValue.value(), ImgList))
                p->置图片组(ImgList);
        }
        XMLRES_置控件属性(p, hNode);
        XMLRES_置选择列表框属性(p, hNode);
        xml_AddControl(p, hNode);
        return p->getHwnd();
    }
    else
        delete p; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置选择列表框属性(zyListBoxEx* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        else if (!wcscmp(name, L"背景图显示方式")) {
           // ptr->背景图显示方式(attr.as_int());
        }
        else if (!wcscmp(name, 资源名_背景图)) {
            //ptr->背景图(attr.as_int());
        }
        else if (!wcscmp(name, L"显示检查框")) {
            ptr->显示检查框(attr.as_bool());
        }
        else if (!wcscmp(name, L"绘制焦点")) {
            ptr->绘制焦点(attr.as_bool());
        }
    }
    for (pugi::xml_node node1 : node.children()) {
        const wchar_t* name1 = node1.name();
        if (!wcscmp(name1, L"项目")) {
            std::wstring text = node1.attribute(资源名_标题).value();
            int lparam = node1.attribute(L"项目数值").as_int(0);
            int iImage = node1.attribute(L"图片索引").as_int(-1);
            int itemHeight = node1.attribute(L"项目高度").as_int(20);
            int selText = node1.attribute(L"选择文本色").as_int(0);
            int selBack = node1.attribute(L"选择背景色").as_int(0);
            int index = ptr->加入项目(text, lparam, iImage, itemHeight);
            if (index != -1) {
                //ptr->置选择项目文本色(index, selText);
                //ptr->置选择项目背景色(index, selBack);
            }

        }
        // 如果当前节点有子节点，则递归解析子节点
        if (node1.first_child()) {
            XMLRES_置选择列表框属性(ptr, node);
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建月历(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 220;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 180;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    bool pVal = hNode.attribute(L"不显示今天").as_bool();
    if (pVal) {
        xrcs.style |= MCS_NOTODAY;
    }
    else {
        xrcs.style &= ~MCS_NOTODAY;
    }
    pVal = hNode.attribute(L"不圈注今天").as_bool();
    if (pVal) {
        xrcs.style |= MCS_NOTODAYCIRCLE;
    }
    else {
        xrcs.style &= ~MCS_NOTODAYCIRCLE;
    }
    pVal = hNode.attribute(L"多选").as_bool();
    if (pVal) {
        xrcs.style |= MCS_MULTISELECT;
    }
    else {
        xrcs.style &= ~MCS_MULTISELECT;
    }
    zyMonthCal* button = new zyMonthCal();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置月历属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置月历属性(zyMonthCal* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"开始星期首日")) {
            ptr->开始星期首日(attr.as_int());
        }
        else if (!wcscmp(name, L"最小日期")) {
            ptr->最小日期(attr.as_int());
        }
        else if (!wcscmp(name, L"最大日期")) {
            ptr->最大日期(attr.as_int());
        }
        else if (!wcscmp(name, L"今天")) {
            ptr->今天(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建日期框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 180;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = DTS_LONGDATEFORMAT;
    }
    bool pVal = hNode.attribute(L"时间格式").as_bool();
    if (pVal) {
        xrcs.style |= DTS_TIMEFORMAT;
    }
    else {
        xrcs.style &= ~DTS_TIMEFORMAT;
    }
    zyDateTimePick* button = new zyDateTimePick();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置日期框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置日期框属性(zyDateTimePick* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"自定义格式")) {
            ptr->置日期格式(attr.value());
        }
        else if (!wcscmp(name, L"最小时间")) {
            ptr->最小时间(attr.as_int());
        }
        else if (!wcscmp(name, L"最大时间")) {
            ptr->最大时间(attr.as_int());
        }
        else if (!wcscmp(name, L"今天")) {
            ptr->今天(attr.as_int());
        }
    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建IP编辑框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = WS_TABSTOP;
    }
    if ((xrcs.flages & XRF_exStyle) == 0) {
        xrcs.ExStyle = WS_EX_CLIENTEDGE;
    }
    zyIPAddress* button = new zyIPAddress();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置IP编辑框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置IP编辑框属性(zyIPAddress* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"地址")) {
            ptr->置地址文本(attr.value());
        }

    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建热键框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 100;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_exStyle) == 0) {
        xrcs.ExStyle = WS_EX_CLIENTEDGE;
    }
    zyHotkeyBox* button = new zyHotkeyBox();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置热键框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置热键框属性(zyHotkeyBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"地址")) {
            //ptr->置地址文本(attr.value());
        }

    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建超链接框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 120;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 22;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = LWS_TRANSPARENT | WS_TABSTOP;
    }
    zyLinkBox* button = new zyLinkBox();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置超链接框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置超链接框属性(zyLinkBox* ptr, pugi::xml_node node)
{
    pugi::xml_node node1 = node.child(L"内容");
    if (node1) {
        // 获取CDATA部分的内容
        std::wstring base64Data = node1.child_value();
        ptr->置文本(base64Data);
    }

    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"链接ID")) {
            ptr->置链接ID(0,attr.value());
        }

    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建影像框(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 120;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 120;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    if ((xrcs.flages & XRF_style) == 0) {
        xrcs.style = ACS_CENTER | ACS_TRANSPARENT;
    }
    zyAnimateBox* button = new zyAnimateBox();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置影像框属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置影像框属性(zyAnimateBox* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, L"文件名")) {
            if(ptr->打开(attr.value()))
                ptr->播放();
        }

    }
}
HWND BlackMoonUI::zyXMLRes::XMLRES_创建透明标签(HWND parent, XmlResCreateStruct& xrcs, pugi::xml_node hNode) {//成功返回控件指针，失败返回0 
    if ((xrcs.flages & XRF_name) == 0) {
        xrcs.lpszName = L"";
    }
    if ((xrcs.flages & XRF_cx) == 0) {
        xrcs.cx = 80;
    }
    if ((xrcs.flages & XRF_cy) == 0) {
        xrcs.cy = 32;
    }
    if ((xrcs.flages & XRF_id) == 0) {
        xrcs.id = 黑月默认ID();
    }
    zyAlphaLabel* button = new zyAlphaLabel();
    bool result = button->创建(parent, xrcs.lpszName, POINT{ xrcs.x, xrcs.y }, POINT{ xrcs.cx, xrcs.cy }, xrcs.id, xrcs.style, xrcs.ExStyle);
    if (result) {
        XMLRES_置控件属性(button, hNode);
        XMLRES_置透明标签属性(button, hNode);
        xml_AddControl(button, hNode);
        return button->getHwnd();
    }
    else
        delete button; // 确保在创建失败时释放内存
    return 0;
}
void BlackMoonUI::zyXMLRes::XMLRES_置透明标签属性(zyAlphaLabel* ptr, pugi::xml_node node)
{
    for (pugi::xml_attribute attr : node.attributes()) {
        // 根据节点名称设置控件类型和风格
        const wchar_t* name = attr.name();
        if (!wcscmp(name, 资源名_文本色)) {
            ptr->文本色(attr.as_int());
        }
        if (!wcscmp(name, 资源名_背景色)) {
            ptr->背景色(attr.as_int());
        }
        if (!wcscmp(name, L"对齐方式")) {
            ptr->对齐方式(attr.as_int());
        }
        if (!wcscmp(name, L"自动换行")) {
            ptr->自动换行(attr.as_bool());
        }
        if (!wcscmp(name, L"垂直显示")) {
            ptr->垂直显示(attr.as_bool());
        }
    }
}